<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;

class Brand extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'brand';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = 'delete_time';

    // 追加属性
    protected $append = [
	    'status_text'
    ];
	
	const STATUS_Y = 1;
	const STATUS_D = 0;
	
	public static $statusList = [
		self::STATUS_Y => '正常',
		self::STATUS_D => '禁用'
	];
	
	public function getStatusTextAttr($value, $data) {
		$value = $value ? : $data['status'];
		$list = self::$statusList;
		return $list[$value] ??'';
	}
	
    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['sort' => $row[$pk]]);
        });
    }

    







}
